Database Query

ABSTRACT

Mechanisms for performing database queries are provided. With these mechanisms, in response to a query request, a query plan intended for minimum query response time and a query plan intended for minimum query total time for the query request are obtained execution of the minimum query response time query plan and the minimum query total time query plan is started. Before the execution of the minimum query total time query plan reaches a specified point, an initial query result obtained from the execution of the minimum query response time query plan is output. In response to the execution of the minimum query total time query plan reaching the specified point, continuing the execution of the minimum query total time query plan to output remaining query results.

BACKGROUND

Embodiments of the present invention generally relate to a databasemanagement system, and more specifically, to a method and system fordatabase query.

A database is a warehouse for organizing, storing and managing dataaccording to a structure of the data. A relational database is acurrently common type of database where data in a relational databaseare currently queried using the Structured Query Language (SQL) whosefunctions include query, manipulation, definition, and control. SQL is acomprehensive, general-purpose relational database language and also ahighly non-procedural language. That is, SQL only requires users toindicate what to do, without indicating how to do the operation. SQLintegrates all operations during a database lifecycle. Moreover, SQLprovides methods of interacting with a relational database and canco-work with standard programming languages.

A database management system (referred as “DBMS” for short) is a largesoftware suite for establishing, using, manipulating and managingdatabases. A database management system manages and controls databasesin a unified manner, so as to ensure safety and integrity of databases.Existing relational database management systems include SQL Server,Sybase, Informix, Oracle, DB2 available from International BusinessMachines (IBM) Corporation, etc. All query engines (also known as QueryExecution Runtime) of a database management system support the queryfunction using SQL. A user or an application may use SQL to query amanaged database by a query engine of a database management system. Aresult of the query usually includes a plurality of records. The timeelapsed before the first item of data conforming to the query conditionis returned is usually referred to as the query response time, and thetime elapsed before a set of all data results conforming to the querycondition is returned is referred to as a query total time.

Upon receipt of a query request, as far as possible, a current databasemanagement system may use minimum total time for query by default, andwill generate a query access plan that can return complete query resultsin the most efficient way to the user or the application issuing thequery. Sometimes, the user or application issuing the query tends toobtain the first several query results as soon as possible, withoutcaring about the time elapsing during the entire query. Such anapplication may use the statement “OPTIMIZED FOR FIRST N ROW” to notifya query engine optimizer of the database management system to executethe query in minimum query response time instead of minimum query totaltime.

However, many applications need to execute a query in both minimum queryresponse time and minimum query total time. For example, when anapplication issuing a query makes a query request, the application mayneed to obtain a response from a database as soon as possible and thenobtain several initial query results so that the application can judgewhether or not to execute a subsequent query or other business logics.Current database management systems can only provide query plans inminimum query response time or provide query plans in minimum querytotal time, whereas none of these query plans can reduce both the queryresponse time and the query total time.

SUMMARY

There is a need for a novel method of database query, which method makesit possible for a user or an application, while querying a database, toexecute the query with both minimum query response time and minimumquery total time, so as to satisfy the user's or the application'srequirements on database query.

According to an aspect of the present invention, there is provided amethod of database query. The method comprises, in response to a queryrequest, obtaining a query plan intended for minimum query response timeand a query plan intended for minimum query total time for the queryrequest. The method further comprises starting execution of the queryplan intended for minimum query response time and execution of the queryplan intended for minimum query total time. Moreover, the methodcomprises outputting, before the execution of the query plan intendedfor minimum query total time reaches a specified point, an initial queryresult obtained from the execution of the query plan intended forminimum query response time. Furthermore, the method comprises, inresponse to the execution of the query plan intended for minimum querytotal time reaching the specified point, continuing the execution of thequery plan intended for minimum query total time to output remainingquery results.

According to another aspect of the present invention, there is provideda system for database query. The system comprises a processor and amemory coupled to the processor, the memory comprising instructions thatwhen executed by the processor cause the processor to obtain, inresponse to a query request, a query plan intended for minimum queryresponse time and a query plan intended for minimum query total time forthe query request. The instructions further cause the processor toexecute the query plan intended for minimum query response time and thequery plan intended for minimum query total time. Moreover theinstructions cause the processor to detect whether the execution of thequery plan intended for minimum query total time reaches a specifiedpoint. In addition, the instructions cause the processor to output queryresults. Before detecting that the execution of the query plan intendedfor minimum query total time reaches the specified point, an initialquery result obtained from the execution of the query plan intended forminimum query response time is output. In response to detecting that theexecution of the query plan intended for minimum query total timereaches the specified point, the processor continues the execution ofthe query plan intended for minimum query total time to cause theremaining query results to be output.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

The above and other objectives, features, and advantages of the presentinvention will become more apparent from the more detailed descriptionof exemplary embodiments of the present invention, when taken inconjunction with the accompanying drawings wherein like numerals usuallydenote the same components in the exemplary embodiments of the presentinvention.

FIG. 1 shows an exemplary computer system 100 which is suitable forimplementing embodiments of the present invention;

FIG. 2 shows an exemplary query request and its two correspondingtables;

FIG. 3 shows an operation mode of a hash join;

FIG. 4 shows steps of a novel method of database query according to thepresent invention; and

FIG. 5 shows a structural block diagram of a system for database queryaccording to the present invention.

DETAILED DESCRIPTION

Illustrative embodiments of the present invention will be described inmore detail with reference to the figures that illustrate theseillustrative embodiments. However, the present invention may beimplemented in various forms and should not be construed as beinglimited to embodiments described here. On the contrary, theseembodiments are provided in order to make the present invention morethorough and complete and to fully convey the scope of the presentinvention to those skilled in the art.

FIG. 1 shows an exemplary computer system 100 which is suitable forimplementing illustrative embodiments of the present invention. As shownin FIG. 1, the computer system 100 may include: CPU (Central ProcessUnit) 101, RAM (Random Access Memory) 102, ROM (Read Only Memory) 103, asystem bus 104, a hard drive controller 105, a keyboard controller 106,a serial interface controller 107, a parallel interface controller 108,a display controller 109, a hard drive 110, a keyboard 111, serialperipheral device 112, parallel peripheral device 113 and a display 114.Among the above devices, the CPU 101, RAM 102, ROM 103, hard drivecontroller 105, keyboard controller 106, serial interface controller107, parallel interface controller 108 and display controller 109 arecoupled to the system bus 104. The hard drive 110 is coupled to the harddrive controller 105. The keyboard 111 is coupled to the keyboardcontroller 106. The serial peripheral equipment 112 is coupled to theserial interface controller 107. The parallel peripheral Equipment 113is coupled to the parallel interface controller 108. Moreover, thedisplay 114 is coupled to the display controller 109. It should beunderstood that the structural block diagram as shown in FIG. 1 is onlyfor exemplary purposes and is not intended to state or imply anylimitation to the present invention. In some cases, some devices may beadded to or removed from this exemplary computer system 100 based onspecific situations.

In database applications, data are usually present in a plurality ofcorrelated tables, and it is rare for data to be present only in onetable. A dataset of a small application system would have dozens oftables, while a dataset of a large system may have thousands of tables.Hence, users and database applications often have to make data queriesin a large dataset comprising multiple tables, i.e. using a multi-tablecorrelated query. A multi-table correlated query generally uses thetable joining technique, which is quite time-consuming. Generallyspeaking, only such a multi-table correlated query has the necessity ofbeing executed with both minimum query response time and minimum querytotal time, while a query in a single table usually has a very quickresponse. If users or applications have the above requirements, it isonly required to run the query with the minimum query total time.

Considering an example where the join operation of a query is performedon two tables in a database, a multi-table correlated operation may beregarded as a combination of several groups correlating the two tables.FIG. 2 shows an exemplary query request and its two correspondingtables. In the following description, a method of the present inventionand its various implementations are explained with this example. Thejoin operation of the query may also be an operation performed on aplurality of intermediate result sets of queries in the database or anoperation performed on tables and intermediate query result sets. Hence,those skilled in the may appreciate that one or both of table T1 andtable T2 may also be query result intermediate set(s). In FIG. 2, thereare two tables whose common column is Product_id, and a query statementreads Select * from T1, T2 where T1. Product_id=T2. Product_id.

The table join technique used by multi-table correlated query includesnested loop join, hash join and sort merge join. The nested loop joinworks in the following mode: first, selecting a table as a driving tableof join, e.g., table T1 in FIG. 2; then extracting eligible records fromdriving table T1; and finally performing a correlated query on a joincolumn in a driven table, e.g., table T2 in FIG. 2, to obtain eligiblerecords. During this process, the first eligible record is firstextracted from driving table T1, then a correlated query is performed onthe join column in driven table T2, thereby obtaining correspondingrecord row. In the process of the correlated query, other recordsconforming to the condition are continuously extracted from drivingtable T1 and subjected to the correlated query with driven table T2.Instead of waiting for the entire flow to end and returning a resultset, result sets obtained from the query are continuously returned. Inthis case, an end user will obtain the first batch of returned recordssoon. Hence, the nested loop join returns first several records veryquickly. The nested loop join is suitable for queries that have strongselectivity, high constraints and require returning of a result set ofonly a small part of records.

FIG. 3 shows an operation mode of the hash join. According to thisfigure, the operation mode of the hash join is divided into two stages:first, in a construction stage, the query engine optimizer first selectsa table, e.g., table T2 in FIG. 3, and applies a hash function on thejoin column in table T2 (i.e. column Product_id in table T2) to generatea hash table through calculations. Next, in a detection stage, the queryengine optimizer applies the same hash function on the join column(i.e., column Product_id in table T1) of each record in the other table(e.g., table T1 in FIG. 2) to obtain a hash value through calculationand looking up a matching hash value in the generated hash table. Fortable T2 with a larger data amount, the construction stage of the hashjoin consumes longer time in initializing the hash table. In adistributed database environment, however, if data need to be extractedremotely, the construction time will be extended further. Therefore, thehash join has a longer query response time. On the other hand, oncecreation of the hash table is completed, all query result sets can beobtained quickly. Therefore, the hash join is more suitable for queriesthat require less query total time to return a large amount of resultset data.

The sort merge join is relatively simple. Just like the hash join, thesort merge join works in a mode that is divided into two stages. First,in a construction stage, the query engine optimizer first sorts a largerone of the two tables according to the join column, i.e. sortingaccording to column Product_id in table T2 in FIG. 2, which sortingconsumes a relatively long time. Then, in a running stage, the queryengine optimizer first sorts the other of the two tables, i.e. table T1in FIG. 2, according to column Product_id as well. Since the table issmaller, the sorting time is shorter. The query engine optimizer mergejoins the two sorted tables directly, and extracts records conforming tothe condition, thereby obtaining query results. Once the sorting isended, all query results can be obtained rapidly. Therefore, comparedwith the nested loop join, the sort merge join is more suitable forqueries that require less query total time to return results with alarge data amount.

In the prior art, for a join query with a large data set, the queryengine optimizer of the database management system usually selects thehash join or the sort merge join in order to obtain a better query totaltime. If it is mandatory that the query engine optimizer of the databasemanagement system obtain a better query response time, the query engineoptimizer will select the nested loop join.

These three join modes are compared below in table 1. As seen from table1, different join types have distinct advantages and join types may bedivided into two main classes: joins with minimum query total time, andjoins with minimum query response time. Accordingly, the query engineoptimizer may output query plans that have minimum query total time andare established by joins with minimum query total time, and query plansthat have minimum query total time and are established by joins withminimum query response time.

TABLE 1 Comparison of Three Join Modes Join Type Advantage For LargeData Set sort merge join less query total time fast hash join less querytotal time fast nested loop join less query response time slow

In view of the above analysis, the present invention proposes a novelmethod of database query, which method can ensure both minimum querytotal time and minimum query response time.

FIG. 4 shows steps of the novel method of database query according toone illustrative embodiment of the present invention. According to FIG.4, in step S401, in response to a query request, a query plan intendedfor minimum query response time and a query plan intended for minimumquery total time are obtained for the query request. In step S402, thequery plan intended for minimum query response time and the query planintended for minimum query total time start to be executed. In stepS403, an initial query result obtained from the execution of the queryplan intended for minimum query response time is outputted before theexecution of the query plan intended for minimum query total timereaches a specified point. In step S404, in response to the execution ofthe query plan intended for minimum query total time reaching thespecified point, the execution of the query plan intended for minimumquery response time is continued in order to output remaining queryresults.

In the method as shown in FIG. 4, such a correlated query might comefrom, for example, a user, an application, or even a query requestinside a database, i.e., a united query performed on intermediate queryresults inside a database query engine so as to accomplish a complexquery request. Therefore, a join operation corresponding to such a querymay be performed on two tables in a database, two intermediate queryresult sets, or a table and an intermediate query result set.

In one illustrative embodiment, in response to the execution of thequery plan intended for minimum query total time reaching the specifiedpoint, the execution of the query plan intended for minimum queryresponse time may be suspended so as to save CPU time, or the executionof the query plan intended for minimum query response time might not besuspended, while its subsequent query results are not adopted.

In an embodiment, the query plan intended for minimum query responsetime is a query plan using the nested loop join, and the query planintended for minimum query total time is a query plan using the hashjoin. In this embodiment, an initial query result may be providedquickly while the query plan using the nested loop join is beingexecuted. Specifically, for the example shown in FIG. 2, if table T2 isrelatively large, T1 may be selected as the driving table of the nestedloop join meanwhile serving as the other table in the construction stageof the hash join. In this embodiment, for each record in table T1, thequery plan using the nested loop join performs a correlated query withthe join column in table T2 to obtain a corresponding record row, i.e.,judging whether or not a record matches. If so, it indicates that therecord is a record in an outputted result and may be outputted; if not,the record is skipped, and the query plan continues to judge whether ornot the next record matches. In the meantime, the hash join applies ahash function to calculate a hash value of each data item in columnProduct_id in table T2 and thereby generates a hash table. Once the hashtable is generated, it indicates that the construction stage of the hashjoin ends. Here, the specified point to be reached by the execution ofthe query plan intended for minimum query total time refers to a pointwhere the construction stage of the hash join ends. For the point wherethe construction stage of the hash join ends, queries may be repeatedlyperformed inside the database query engine until the point is reached.Alternatively, an event mechanism may be used inside the hash join suchthat once the execution of a relevant program of the hash join reachesthe point, the query engine is notified. Then, the query engine maysuspend the execution of the query plan intended for minimum queryresponse time. The execution of the hash join plan is continued, andremaining query results are outputted.

In one illustrative embodiment where the execution of the hash join planis continued and remaining query results are output, the hash join isnot performed on records in driving table T1 on which the nested loopjoin plan has been performed. Hence, the execution of the hash join iscontinued from the first record in table T1 which is not yet subjectedto the nested loop join, i.e., performing the detection stage of thequery plan using the hash join; applying the same hash function on therecord to calculate a hash value of the join column of the record;matching the hash value with the hash table obtained from table T2. Ifthere is a matching value, it indicates that the record is an outputtedresult and may be outputted; otherwise, the above process is continuedto the next record in table T1.

In another illustrative embodiment, the query plan intended for minimumquery response time is a query plan using the nested loop join, and thequery plan intended for minimum query total time is a query plan usingthe sort merge join. In this embodiment, an initial query result may beprovided quickly with the query plan using the nested loop join is beingexecuted. Specifically, for the example shown in FIG. 2, if table T2 isrelatively large, T1 may be selected as the driving table of the nestedloop join. In this embodiment, for each record in table T1, the queryplan using the nested loop join performs a correlated query with thejoin column in table T2 to obtain a corresponding record row, i.e.,judging whether or not a record matches. If so, it indicates that therecord is a record in an outputted result and may be outputted; if not,the record is skipped, and the query plan continues to judge whether ornot the next record is matching. In the meantime, in the constructionstage of the sort merge join, for the other table that is not a drivingtable, namely, table T2, it is sorted according to column Product_id toobtain a sorted table for the other table, which can be stored using atemporary table. Once the sorting of table T2 is completed, it indicatesthat the construction stage of the sort merge join ends. Here, thespecified point to be reached by the execution of the query planintended for minimum query total time refers to a point where theconstruction stage of the sort merge join ends. For the point where theconstruction stage of the sort merge join ends, queries may be performedrepeatedly inside the database query engine until the point is reached.Alternatively, an event mechanism may be used inside the sort merge joinsuch that once the point is reached, the query engine is notified. Then,the query engine may suspend the execution of the query plan intendedfor minimum query response time. The execution of the sort merge joinplan is continued, and remaining query results are outputted.

In an embodiment where the execution of the sort merge plan is continuedand remaining query results are outputted, the sort merge join is notperformed on records in driving table T1 on which the nested loop joinplan has been performed. That is, for those records on which the nestedloop join plan has been performed in the driving table of the query planusing the nested loop join, no operation of the execution stage of thequery plan using the sort merge join is performed. In this manner, threesteps are comprised: first, removing from the driving table records onwhich the query plan using the nested loop join has been performed;sorting the driving table according to the join column to obtain asorted table of a remaining driving table; and then performing a mergejoin operation on the sorted table of the remaining driving table andthe sorted table of the other table to obtain the remaining queryresults.

In another illustrative embodiment where the execution of the query planintended for minimum query total time is continued and remaining queryresults are outputted, three steps are comprised as follows: first,storing the initial query result; second, storing all query results ofthe query plan intended for minimum query total time; and finally,removing the initial query result from the all query results to therebyobtain the remaining query results. The above embodiment may have manyvariations. For example, a temporary table may be used to store aninitial query result obtained from the execution of the query planintended for minimum query response time; when an execution result ofthe query plan intended for minimum query total time is obtained,another temporary table may be used to store the result. Then, the twotables are merged, and repetitive items are removed. In this way, thequery results to be outputted ultimately are obtained. Alternatively,the results are compared with a temporary table, and data items of thetemporary table which are contained in the temporary table are removed,so as to obtain the query results to be outputted. Further, during theexecution of the query plan intended for minimum query total time, eachtime a query result of the execution of the query plan intended forminimum query total time is obtained, the result is compared with a dataitem in a temporary table. If the result and the data item are the same,then the data item is not outputted; otherwise the data item isoutputted. Further, there are many equivalent embodiments. For example,the number of data items in a temporary table is obtained; each time aquery result of the execution of the query plan intended for minimumquery total time is obtained, it is compared with a data item in thetemporary table; if they are the same, then the data item is notoutputted, and a counter is used to count; otherwise the data item isoutputted. When a count result of the counter is equal to the number ofdata items in the temporary table, no comparison is made any more, suchthat all subsequent query results are outputted directly. In thismanner, the query total time is reduced further.

In another illustrative embodiment, the initial query result obtainedfrom the execution of the query plan intended for minimum query responsetime may be stored in a memory or cache or other storage componentrather than in a temporary table, and query results to be outputtedultimately are obtained using a method similar to the foregoing.

In a further illustrative embodiment, a cost-based model of the currentdatabase query engine optimizer may be used to evaluate a cost forjoining these two tables or two intermediate query result sets or atable and an intermediate query result set, to judge whether the hashjoin or the sort merge join requires a smaller cost, so as to select aproper minimum total time query plan. This embodiment comprises thesteps of: evaluating a hash join query plan and a sort merge join queryplan for the query plan intended for minimum query total time, whereinthe evaluation uses a cost model of the database query engine optimizer;and selecting one of the query plans that requires a smaller cost, asthe query plan intended for minimum query total time. Here, the costmodel calculates respective costs for multiple possible execution plans,and selects an execution plan with the minimum cost to execute SQLstatements, according to current system resources, statisticalinformation, index information of join tables, etc. Existing databasessupport this model, so the principles and usage of the model are notdetailed here.

Under the same inventive concept, the present invention furtherdiscloses a system for database query. FIG. 5 shows a structure of oneillustrative embodiment of the system. According to this figure, thesystem comprises: obtaining means 501 configured to obtain, in responseto a query result, a query plan intended for minimum query response timeand a query plan intended for minimum query total time of the queryrequest; executing means 502 configured to execute the query planintended for minimum query response time and the query plan intended forminimum query total time; controlling means 504 configured to detectwhether the execution of the query plan intended for minimum query totaltime reaches a specified point; outputting means 503 configured tooutput query results; wherein before the controlling means detects thatthe execution of the query plan intended for minimum query total timereaches the specified point, the outputting means outputs an initialquery result obtained from the execution of the query plan intended forminimum query response time; in response to the controlling meansdetecting that the execution of the query plan intended for minimumquery total time reaches the specified point, the executing meanscontinues the execution of the query plan intended for minimum querytotal time so that the outputting means outputs remaining query results.The system for database query as shown in FIG. 5 may be embedded in acurrent database query engine.

In one illustrative embodiment, the query plan intended for minimumquery response time is a query plan using the nested loop join, and thequery plan intended for minimum query total time is a query plan usingthe hash join. The specified point is a point where the constructionstage of the hash join ends. The executing means continuing theexecution of the query plan intended for minimum query total timecomprises: the executing means performing operations of the detectionstage of the query plan using the hash join, from the first record in adriving table of the query plan using the nested loop join on which thenested loop join query plan has not been performed.

In another illustrative embodiment, the query plan intended for minimumquery response time is a query plan using the nested loop join, and thequery plan intended for minimum query total time is a query plan usingthe sort merge join. The specified point is a point where theconstruction stage of the sort merge join ends. The executing meanscontinuing the execution of the query plan intended for minimum querytotal time comprises: the executing means performing no operation of theexecution stage of the query plan using the sort merge join on therecords already subjected to the nested loop join query plan in adriving table of the query plan using the nested loop join query plan.In a more specific embodiment, the executing means comprises: removingmeans configured to sort the driving table according to a join columnafter removing the records already subjected to the nested loop joinquery plan, to obtain a sorted table of the remaining driving table; andmerge joining means configured to perform a merge join operation on thesorted table of the remaining driving table and a sorted table of theother table to obtain the remaining query results.

In a further illustrative embodiment, the executing means furthercomprises: initial query result storing means configured to store theinitial query result; all query results storing means configured tostore all query results of the query plan intended for minimum querytotal time; and remaining query results obtaining means configured toremove the initial query result from the all query results to obtain theremaining query results.

In the system of one illustrative embodiment of the present invention,the query request is made with respect to at least one of: a pluralityof tables, a plurality of intermediate query result sets, or a table andan intermediate query result set.

In a still further illustrative embodiment, the system further comprises(not shown in FIG. 5): evaluating means configured to evaluate a queryplan using hash join and a query plan using sort merge join for thequery plan intended for minimum query total time, wherein the evaluatingmeans uses a cost model of the database query engine optimizer; andselecting means configured to select one of the two query plans thatrequires a smaller cost, as the query plan intended for minimum querytotal time.

The present invention can be implemented in software, hardware orcombination of hardware components and hardware components. In apreferred embodiment, the present invention is implemented as software,including, without limitation to, firmware, resident software,micro-code, etc.

Moreover, the present invention may be implemented as a computer programproduct accessible by computer-usable or computer-readable media thatprovide program code for use by or in connection with a computer or anyinstruction executing system. For the purpose of description, acomputer-usable or computer-readable medium may be any tangible meansthat can contain, store, communicate, propagate, or transport theprogram for use by or in connection with an instruction executionsystem, apparatus, or device.

The medium may be an electric, magnetic, optical, electromagnetic,infrared, or semiconductor system (apparatus or device), or propagationmedium. Examples of the computer-readable medium would include thefollowing: a semiconductor or solid storage device, a magnetic tape, aportable computer diskette, a random access memory (RAM), a read-onlymemory (ROM), a hard disk, and an optical disk. Examples of the currentoptical disk include a compact disk read-only memory (CD-ROM), compactdisk-read/write (CD-R/W), and DVD.

A data processing system adapted for storing and/or executing programcode would include at least one processor that is coupled to a memoryelement directly or via a system bus. The memory element may include alocal memory usable during actually executing the program code, a massmemory, and a cache that provides temporary storage for at least oneportion of program code so as to decrease the number of times forretrieving code from the mass memory during execution.

An Input/Output or I/O device (including, without limitation to, akeyboard, a display, a pointing device, etc.) may be coupled to thesystem directly or via an intermediate I/O controller.

A network adapter may also be coupled to the system such that the dataprocessing system can be coupled to other data processing systems,remote printers or storage devices via an intermediate private or publicnetwork. A modem, a cable modem, and an Ethernet card are merelyexamples of a currently available network adapter.

It is to be understood from the foregoing description that modificationsand alterations may be made to the respective embodiment of the presentinvention without departing from the real spirit of the presentinvention. The description in this specification is for purposes ofillustration only, and should not be construed as limiting. The scope ofthe present invention is only defined by the appended claims.

1. A method of database query, comprising: in response to a queryrequest, obtaining a first query plan for minimum query response timeand a second query plan for minimum query total time for the queryrequest; starting execution of the first query plan and execution of thesecond query plan; outputting, before execution of the second query planreaches a specified point, an initial query result obtained fromexecution of the first query plan; and in response to execution of thesecond query plan reaching the specified point, continuing execution ofthe second query plan to output remaining query results.
 2. The methodaccording to claim 1, wherein the first query plan is a query plan usinga nested loop join operation, the second query plan is a query planusing a hash join operation, and the specified point is a point where aconstruction stage of the hash join operation ends.
 3. The methodaccording to claim 2, wherein continuing execution of the second queryplan comprises: performing operation of a detection stage of the secondquery plan using the hash join operation, from a first record on whichthe nested loop join operation has not been performed in a driving tableof the first query plan.
 4. The method according to claim 1, wherein thefirst query plan is a query plan using a nested loop join operation, thesecond query plan is a query plan using a sort merge join operation, andthe specified point is a point where a construction stage of the sortmerge join operation ends.
 5. The method according to claim 4, whereinin the construction stage of the sort merge join operation, anothertable which is not a driving table of the first query plan is sortedaccording to a join column to obtain a sorted table of the anothertable, and wherein continuing execution of the second query plancomprises: performing no operation of an execution stage of the secondquery plan using the sort merge join on records already subjected to thenested loop join operation of the first query plan in the driving tableof the first query plan.
 6. The method according to claim 5, wherein theperforming no operation of an execution stage of the second query planusing the sort merge join on records already subjected to the nestedloop join operation of the first query plan in the driving table of thefirst query plan comprises: sorting the driving table according to thejoin column after removing the records already subjected to the nestedloop join operation of the first query plan, to obtain a sorted table ofa remaining driving table; and performing a merge-join operation on thesorted table of the remaining driving table and the sorted table of theother table to obtain the remaining query results.
 7. The methodaccording to claim 2, wherein continuing execution of the second queryplan to output remaining query results comprises: storing the initialquery result; storing all query results of the second query plan; andremoving the initial query result from the all query results to obtainthe remaining query results.
 8. The method according to claim 1, whereinthe query request is made for at least one of: a plurality of tables; aplurality of intermediate query result sets; and a table and anintermediate query result set in the database.
 9. The method accordingto claim 1, before obtaining a first query plan and a second query planfor the query request, further comprising: evaluating a hash join queryplan that uses a hash join operation and a sort merge join query planthat uses a sort merge join operation for the second query plan based ona cost model in a database query engine optimizer; and selecting one ofthe hash join query plan or the sort merge join query which requires asmaller cost, as the second query plan.
 10. A system for database query,comprising: obtaining means configured to obtain, in response to a queryrequest, a first query plan for minimum query response time and a secondquery plan for minimum query total time for the query request; executingmeans configured to execute the first query plan and the second queryplan; controlling means configured to detect whether execution of thesecond query plan reaches a specified point; and outputting meansconfigured to output query results; wherein before the controlling meansdetects that the execution of the second query plan reaches thespecified point, the outputting means outputs an initial query resultobtained from the execution of the first query plan, and wherein inresponse to the controlling means detecting that the execution of thesecond query plan reaches the specified point, the executing meanscontinues the execution of the second query plan to cause the outputtingmeans to output remaining query results.
 11. The system according toclaim 10, wherein the first query plan is a query plan using a nestedloop join operation, the second query plan is a query plan using a hashjoin operation, and the specified point is a point where a constructionstage of the hash join operation ends.
 12. The system according to claim11, wherein the executing means continuing the execution of the secondquery plan comprises: the executing means performing operations of adetection stage of the second query plan using the hash join operation,from a first record on which the nested loop join operation has not beenperformed in a driving table of the first query plan.
 13. The systemaccording to claim 10, wherein the first query plan is a query planusing a nested loop join operation, the second query plan is a queryplan using a sort merge join operation, and the specified point is apoint where a construction stage of the sort merge join operation ends.14. The system according to claim 13, wherein in the construction stageof the sort merge join operation, another table which is not a drivingtable of the first query plan is sorted according to a join column toobtain a sorted table of the another table, and wherein the executingmeans continuing the execution of the second query plan comprises: theexecuting means performing no operation of an execution stage of thesecond query plan using the sort merge join on records already subjectedto the nested loop join operation of the first query plan in the drivingtable of the first query plan.
 15. The system according to claim 14,wherein the executing means comprises: removing means configured to sortthe driving table according to the join column after removing recordsalready subjected to the nested loop join operation of the first queryplan, to obtain a sorted table of a remaining driving table; andmerging-joining means configured to perform a merge-join operation onthe sorted table of the remaining driving table and the sorted table ofthe other table to obtain the remaining query results.
 16. The systemaccording to claim 11, wherein the executing means further comprises:initial query result storing means configured to store the initial queryresult; all query results storing means configured to store all queryresults of the second query plan; and remaining query result removingmeans configured to remove the initial query result from the all queryresults to obtain the remaining query results.
 17. The system accordingto claim 10, wherein the query request is made for at least one of: aplurality of tables; a plurality of intermediate query result sets; anda table and an intermediate query result set in the database.
 18. Thesystem according to claim 10, further comprising: evaluating meansconfigured to evaluate a hash join query plan that uses a hash joinoperation and a sort merge join query plan that uses a sort merge joinoperation for the second query plan based on a cost model in a databasequery engine optimizer; and selecting means configured to select one ofthe hash join query plan or the sort merge join query which requires asmaller cost, as the second query plan.
 19. A computer program productcomprising a computer readable storage medium having a computer readableprogram stored therein, wherein the computer readable program, whenexecuted on a computing device, causes the computing device to: inresponse to a query request, obtain a first query plan for minimum queryresponse time and a second query plan for minimum query total time forthe query request; start execution of the first query plan and executionof the second query plan; output, before execution of the second queryplan reaches a specified point, an initial query result obtained fromexecution of the first query plan; and in response to execution of thesecond query plan reaching the specified point, continue execution ofthe second query plan to output remaining query results.
 20. Anapparatus, comprising: a processor; and a memory coupled to theprocessor, wherein the memory comprises instructions which, whenexecuted by the processor, cause the processor to: obtain, in responseto a query request, a first query plan for minimum query response timeand a second query plan for minimum query total time for the queryrequest; start execution of the first query plan and execution of thesecond query plan; output, before execution of the second query planreaches a specified point, an initial query result obtained fromexecution of the first query plan; and continue, in response toexecution of the second query plan reaching the specified point,execution of the second query plan to output remaining query results.